<template>
	<view class="content">
		<u-cell-group>
				<u-cell-item  title="药品" :value="druginfo.tradeName" @click="back"></u-cell-item>
<!-- 				<u-cell-item  title="剂量" :arrow="false">
					<u-number-box v-model="dosevalue" @change="valChange"></u-number-box>
					&nbsp;{{druginfo.doseUnit}}
				</u-cell-item> -->
				<u-cell-item  title="频次" :value="frequency" @click="choosefrequency" ></u-cell-item>
				<u-select v-model="showfrequency" :list="frequencylist" @confirm="confirmfrequency"></u-select>
				<u-cell-item  title="用法" :value="usage" @click="chooseusage" ></u-cell-item>
				<u-select v-model="showusage" :list="usagelist" @confirm="confirmusage"></u-select>
				<u-cell-item  title="用药天数" :arrow="false">
					<u-number-box v-model="daysvalue" @change="valChange"></u-number-box>
					&nbsp;天
				</u-cell-item>
				<u-cell-item  title="总量" :arrow="false">
					<u-number-box v-model="totalvalue" @change="valChange"></u-number-box>
					&nbsp;{{druginfo.packUnit}}
				</u-cell-item>
				<u-cell-item :arrow="false">
					<u-input placeholder="请输入备注" v-model="remarks" />
				</u-cell-item>
				<view class="bottombutton1" @click="back()">取消</view>
				<view class="bottombutton2" @click="submitdrug">确定</view>
		</u-cell-group>
		
	</view>
</template>

<script>
	export default {
		data(){
			return{
				index:0,
				basedrug:[],
				druginfo:[],
				dosevalue:0,
				daysvalue:0,
				totalvalue:0,
				usagevalue:1,
				frequencyvalue:1,
				remarks:'',
				usage:"口服",
				showusage:false,
				usagelist:[
					{
						label: '口服',
						value:1
					},
					{
						label: '涂抹',
						value:2
					},
					{
						label: '静脉注射',
						value:3
					},
					{
						label: '皮下注射',
						value:4
					}
				],
				frequency:"bid",
				showfrequency:false,
				frequencylist: [
					{
						label: 'qd',
						value:1
					},
					{
						label: 'bid',
						value:2
					},
					{
						label: 'tid',
						value:3
					},
					{
						label: 'qid',
						value:4
					},
					{
						label: 'qod',
						value:5
					},
					{
						label: 'qw',
						value:6
					}
				],
			}
		},
		methods:{
			valChange(e) {
			},
			choosefrequency(){
				this.showfrequency=true;
			},
			confirmfrequency(e){
				this.frequency=e[0].label;
				this.frequencyvalue=e[0].value;
			},	
			chooseusage(){
				this.showusage=true;
			},
			confirmusage(e){
				this.usage=e[0].label;
				this.usagevalue=e[0].value;
			},
			submitdrug(){
				var index1=this.usagevalue;
				var index2=this.frequencyvalue;
				var index3=this.index
				var thisdata={
								'drugId':this.druginfo.drugId,
								'name':this.druginfo.drugName,
								'dose':this.druginfo.dose,
								'frequencyCode':this.frequencyvalue,
								'usageCode':this.usagevalue,
								'takeDays':this.daysvalue,
								'quantity':this.totalvalue,
								'remark':this.remarks,
								'price':this.druginfo.price,
								'name1':this.usage,
								'name2':this.frequency
							}
				uni.showModal({
					title: '提示',
					content: '是否提交药品？',
					success: function (res) {
					    if (res.confirm) {
							getApp().globalData.worktable[index3].drugs.push(thisdata),
							uni.redirectTo({
								url:"doctor_dispensing_detail_prescription?index="+index3
							})
						}
					},
				})
				// console.log(this.druginfo.tradeName)
				// console.log(this.dosevalue)
				// console.log(this.daysvalue)
				// console.log(this.usage)
				// console.log(this.remarks)
			},
			back(){
				uni.redirectTo({
					url:"doctor_dispensing_detail_prescriptionlist"
				})
			}
		},
		onLoad:function (option){
			// console.log(option.drugid);
			this.index=option.index;
			this.basedrug=getApp().globalData.baseDrug;
			for(var i=0;i<this.basedrug.length;i++){
				if(this.basedrug[i].drugId==option.drugid){
					this.druginfo=this.basedrug[i]
				}
			}
			// console.log(this.druginfo)
		}
	}
</script>

<style>
	.bottombutton1{
		text-align: center;
		padding: 28rpx;
		font-size: 36rpx;
		width:300rpx;
		position:fixed;
		bottom:0;
		border-radius: 0;
		color: #666666;
		border: 1rpx solid #fff;
	}
	.bottombutton2{
		text-align: center;
		padding: 28rpx;
		margin-left: 300rpx;
		width:500rpx;
		position:fixed;
		bottom:0;
		border-radius: 0;
		color: #FFFFFF;
		background-color:#1477fe;
		font-size: 36rpx;
	}
</style>
